/**
 * 
 */
package com.zastoupil.pgc.blueprint_pattern.xml.compile.bluescript;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.zastoupil.pgc.blueprint_pattern.xml.compile.TerminalExpression;

/**
 * Responsible for representing a String object in the Bluescript scripting
 * language
 * 
 * @author Peter Zastoupil
 * 
 */
public class BluescriptString extends TerminalExpression implements
		BluescriptExpression {

	/*
	 * A String is defined by a sequence of characters surrounded by single
	 * quotation marks
	 */
	private static Pattern _expressionPattern = Pattern
			.compile(BluescriptLexicalStructure.STRING_LITERAL.toString());

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.zastoupil.pgc.blueprint_pattern.xml.compile.AbstractExpression#
	 * getExpressionPattern()
	 */
	@Override
	public Pattern getExpressionPattern() {
		return BluescriptString._expressionPattern;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.zastoupil.pgc.blueprint_pattern.xml.compile.AbstractExpression#
	 * evaluateExpression()
	 */
	@Override
	public Object evaluateExpression() {

		Pattern stringContentPattern = Pattern
				.compile(BluescriptLexicalStructure.STRING_CHARACTERS.toString());
		Matcher stringContentMatcher = stringContentPattern.matcher(this
				.getExpressionString());

		String stringContent = "";

		if (stringContentMatcher.find()) {
			stringContent = stringContentMatcher.group();
		}

		return stringContent;

	}

}
